package com.ruoyi.technology.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.technology.domain.TechnologyDesign;
import com.ruoyi.technology.service.ITechnologyDesignService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工艺设计Controller
 * 
 * @author ruoyi
 * @date 2023-01-13
 */
@Controller
@RequestMapping("/technology/design")
public class TechnologyDesignController extends BaseController
{
    private String prefix = "technology/design";

    @Autowired
    private ITechnologyDesignService technologyDesignService;

    @RequiresPermissions("technology:design:view")
    @GetMapping()
    public String design()
    {
        return prefix + "/design";
    }

    /**
     * 查询工艺设计列表
     */
    @RequiresPermissions("technology:design:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TechnologyDesign technologyDesign)
    {
        startPage();
        List<TechnologyDesign> list = technologyDesignService.selectTechnologyDesignList(technologyDesign);
        return getDataTable(list);
    }

    /**
     * 导出工艺设计列表
     */
    @RequiresPermissions("technology:design:export")
    @Log(title = "工艺设计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TechnologyDesign technologyDesign)
    {
        List<TechnologyDesign> list = technologyDesignService.selectTechnologyDesignList(technologyDesign);
        ExcelUtil<TechnologyDesign> util = new ExcelUtil<TechnologyDesign>(TechnologyDesign.class);
        return util.exportExcel(list, "工艺设计数据");
    }

    /**
     * 新增工艺设计
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存工艺设计
     */
    @RequiresPermissions("technology:design:add")
    @Log(title = "工艺设计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TechnologyDesign technologyDesign)
    {
        return toAjax(technologyDesignService.insertTechnologyDesign(technologyDesign));
    }

    /**
     * 修改工艺设计
     */
    @RequiresPermissions("technology:design:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TechnologyDesign technologyDesign = technologyDesignService.selectTechnologyDesignById(id);
        mmap.put("technologyDesign", technologyDesign);
        return prefix + "/edit";
    }

    /**
     * 修改保存工艺设计
     */
    @RequiresPermissions("technology:design:edit")
    @Log(title = "工艺设计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TechnologyDesign technologyDesign)
    {
        return toAjax(technologyDesignService.updateTechnologyDesign(technologyDesign));
    }

    /**
     * 删除工艺设计
     */
    @RequiresPermissions("technology:design:remove")
    @Log(title = "工艺设计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(technologyDesignService.deleteTechnologyDesignByIds(ids));
    }
}
